package com.example.administrator.foodrowfresh.jiao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.foodrowfresh.R;
import com.example.administrator.foodrowfresh.jiao.modle.PromotionModel;
import com.example.administrator.foodrowfresh.superBase.MyBaseAdapter;

import org.xutils.x;

import java.util.List;

/**
 * 活动首页适配
 * Created by Bob on 2016/4/20.
 */
public class PromotionAdapter extends MyBaseAdapter<PromotionModel.DataBean.ActivityBean> {
    private Context mContext;
    private List<PromotionModel.DataBean.ActivityBean> mDatas;
    private LayoutInflater inflater;
    public PromotionAdapter(List<PromotionModel.DataBean.ActivityBean> datas, Context context) {
        super(datas, context);
        mContext = context;
        mDatas = datas;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHodler hodler;
        if (convertView == null) {
            hodler = new ViewHodler();
           convertView = inflater.from(mContext).inflate(R.layout.promotion_fm_lv_item, parent, false);
            hodler.image = (ImageView) convertView.findViewById(R.id.promotion_fm_lv_item_image);
            hodler.title = (TextView) convertView.findViewById(R.id.promotion_fm_lv_item_title);
            hodler.mBeginTime = (TextView) convertView.findViewById(R.id.promotion_fm_lv_item_time);
            hodler.begin_time = (TextView) convertView.findViewById(R.id.promotion_fm_lv_item_promotion);
            convertView.setTag(hodler);
        } else {
            hodler = (ViewHodler) convertView.getTag();
        }

        hodler.title.setText(mDatas.get(position).getTitle());
        hodler.mBeginTime.setText(mDatas.get(position).getBeginTime());
        hodler.begin_time.setText(mDatas.get(position).getBegin_time());
        //异步加载image
        String pic = mDatas.get(position).getImage();
        x.image().bind(hodler.image,pic);
        return convertView;
    }

    public class ViewHodler {
        TextView title, mBeginTime, begin_time;
        ImageView image;
    }
}
